﻿using UnityEngine;
using System.Collections;

public class BalloonSpawner : ObjectSpawner {

	public GameObject balloonPreFab;
	public int _amountOfBalloons = 5;
	public GUIStyle textStyle;
	public Color colorToKeep;
	private string colorToKeepText = "";
	string InstructionText = "Pop the {0} balloons to win the game";
	// Use this for initialization
	new void Start () {
		SetUp (2.0f, balloonPreFab, this.transform.Find("_Balloons"));
		RandomSpawnPositionsOnScreen(_amountOfBalloons);
		DisplayInstructions(InstructionText, 3, textStyle);
	}
	void RandomSpawnPositionsOnScreen(int amountOfBalloons)
	{
		for (int i = 0; i < amountOfBalloons; i++) {
			Vector3 pos = getRandomPositionOnScreen();
			GameObject balloon = SpawnObjectAt(pos,Quaternion.identity);
			AssignColour(balloon);
		}
		InstructionText = string.Format(InstructionText,colorToKeepText);
	}
	void AssignColour(GameObject balloon)
	{
		var colorInfo = Helper.RandomColour(new string[] { "Blue" , "Green", "Red" });
		balloon.GetComponent<SpriteRenderer>().color = colorInfo.color;
		colorToKeep = colorInfo.color;
		colorToKeepText = colorInfo.colorName;
	}
	// Update is called once per frame
	new void Update () {
		base.Update ();
	}
}
